<template>
  <div class="container">
    <LabelBar v-if="form" label="报告信息" class="item">
      <van-field v-bind="textProps" label="结案单号" :value="form.archiveNo" readonly />
      <van-field v-bind="textProps" label="服务日期" :value="form.serviceDate" readonly />
      <van-field v-bind="textProps" label="维修部件" type="textarea" :value="form.maintainPartsName" readonly />
      <van-field v-bind="textProps" label="部件问题" type="textarea" :value="form.maintainPartsInfo" readonly />
      <van-field v-bind="textProps" label="风机配置" :value="form.winfanConfigName" readonly />
      <van-field v-bind="textProps" label="使用行业" :value="form.applyIndustryName" readonly />
      <van-field v-bind="textProps" label="处理结果" type="textarea" :value="form.serviceResult" readonly />
      <van-field v-bind="textProps" label="客户职务" :value="form.contactPost" readonly />
      <van-field v-bind="textProps" label="客户评价" :value="form.estimate|estimateFilter" readonly />
      <van-field v-bind="textProps" label="实际工时" :value="form.workHours" readonly />
      <van-field v-bind="textProps" label="责任归属" :value="form.responsibilityName" readonly />
      <van-field v-bind="textProps" label="服务性质" :value="form.serviceNature|serviceNatureFilter" readonly />
      <van-field v-bind="textProps" label="二次维修" :value="form.secondMaintain|secondMaintainFilter" readonly />
      <van-field v-bind="textProps" label="费用归属" type="textarea" :value="form.feeBelongName" readonly />
      <van-field v-bind="textProps" label="费用定性" :value="form.feeBelongRemark" readonly />
      <van-field v-bind="textProps" label="厂门照片" readonly>
        <template #input>
          <van-uploader
            v-model="form.doorPicList"
            readonly
            :max-count="1"
            :after-read="file => afterUpload(file, 'doorPic')"
          />
        </template>
      </van-field>
      <van-field v-bind="textProps" label="风机铭牌" readonly>
        <template #input>
          <van-uploader
            v-model="form.winFanPicList"
            readonly
            :max-count="1"
            :after-read="file => afterUpload(file, 'doorPic')"
          />
        </template>
      </van-field>
      <van-field v-bind="textProps" label="其他照片" readonly>
        <template #input>
          <van-uploader
            v-model="form.sceneFilesList"
            readonly
          />
        </template>
      </van-field>
      <van-field v-bind="textProps" label="出厂日期" :value="form.saleDate" readonly />
      <van-field v-bind="textProps" label="风机数量" :value="form.winFanNum" readonly />
      <van-field v-bind="textProps" label="使用时间" :value="form.useDate" readonly />

    </LabelBar>
    <div v-else class="nodata">
      <img src="@/assets/image/nodata.png" alt="">
    </div>

    <div class="btn" @click="jump">
      <img v-if="form" src="@/assets/image/edit.png" alt="">
      <img v-else src="@/assets/image/add.png" alt="">
    </div>

  </div>
</template>

<script>
import LabelBar from '../../components/LabelBar'
import { urlParams, openWx, baseUrl, textProps } from '@/assets/utils'

export default {
  components: { LabelBar },
  filters: {
    feeBelongFilter(key) {
      const map = {
        '01': '计生产',
        '02': '计开发',
        '03': '计供应商',
        '04': '计物流',
        '05': '计业务',
        '06': '计订单',
        '08': '计售后',
        '99': '计总营',
      }
      return map[key] || ''
    },
    maintainPartsFilter(key) {
      const map = {
        '01': '更换配件',
        '02': '叶轮',
        '03': '壳体',
        '04': '隔音箱',
        '05': '传动组',
        '06': '轴',
        '07': '外观',
        '08': '性能',
        '09': '电控',
        '10': '补偿器',
        '99': '其它',
      }
      return map[key] || ''
    },
    estimateFilter(key) {
      const map = { '01': '很满意', '02': '满意', '03': '一般', '04':'不满意', '05': '很不满意' }
      return map[key] || ''
    },
    secondMaintainFilter(key) {
      const map = { '00': '否', '01': '是' }
      return map[key] || ''
    },
    serviceNatureFilter(key) {
      const map = { '03': '无偿服务', '04': '有偿服务' }
      return map[key] || ''
    },
    uploadList(url) {
      return [ { url, isImage: true } ]
    },
  },
  data() {
    return {
      textProps,
      saleServiceId: urlParams.get('saleServiceId'),
      serviceNo: urlParams.get('serviceNo'),
      form: null,

      options: {
        feeBelong: [
          { label: '计生产', value: '01' },
          { label: '计开发', value: '02' },
          { label: '计供应商', value: '03' },
          { label: '计物流', value: '04' },
          { label: '计业务', value: '05' },
          { label: '计订单', value: '06' },
          { label: '计售后', value: '08' },
          { label: '计总营', value: '99' },
        ],

        maintainParts: [
          { label: '更换配件', value: '01' },
          { label: '叶轮', value: '02' },
          { label: '壳体', value: '03' },
          { label: '隔音箱', value: '04' },
          { label: '传动组', value: '05' },
          { label: '轴', value: '06' },
          { label: '外观', value: '07' },
          { label: '性能', value: '08' },
          { label: '电控', value: '09' },
          { label: '补偿器', value: '10' },
          { label: '其它', value: '99' },
        ],
      },
    }
  },
  computed: {},
  watch: {},
  created() {
    this.init()
  },
  mounted() {
  },
  methods: {
    init() {
      this.getDetail()
    },

    async getDetail() {
      const res = await this.server.get('/saleService/findSaleServiceArchiveBySaleServiceId', {
        saleServiceId: this.saleServiceId,
      })
      if (res.code === '0' && res.object) {
        this.form = res.object

        this.form.feeBelongList = this.form.feeBelong.split(',')
        // this.options.feeBelong = this.options.feeBelong.filter(e => )

        // 处理费用归属
        this.form.feeBelongName = this.options.feeBelong
          .filter(e => this.form.feeBelong.includes(e.value))
          .map(e => e.label).join(',')

        this.form.maintainPartsName = this.options.maintainParts
          .filter(e => this.form.maintainParts.includes(e.value))
          .map(e => e.label).join(',')

        if (this.form.doorPic) this.form.doorPicList = [ { url: this.form.doorPic, isImage: true } ]
        if (this.form.winFanPic) {
          this.form.winFanPicList = [ { url: this.form.winFanPic, isImage: true } ]
        }
        if (this.form.sceneFiles) {
          this.form.sceneFilesList = this.form.sceneFiles.map(e => ({
            ...e,
            isImage: true,
          }))
          console.log(this.form.sceneFilesList, 2, this.form.winFanPicList, this.form.doorPicList)
        }
      }
    },

    jump() {
      openWx(`${location.origin}/closingReport.html`, `&archiveNo=${this.form?.archiveNo || ''}`)
    },
  },
}
</script>

<style lang="less" scoped>
.container {
  position: relative;

  .costCheckbox {
    ::v-deep .van-checkbox {
      margin-bottom: 8px;
    }
  }
  .btn{
    position: fixed;
    right: 30px;
    bottom: 80px;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    img{
      width: 100%;
      height: 100%;
    }
  }
}
</style>
